package com.human.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.human.entity.Empsalary;
import com.human.dao.EmpsalaryMapper;
import com.human.entity.ResultVo;
import com.human.service.IEmpsalaryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 员工工资 服务实现类
 * </p>
 *
 * @author jzq
 * @since 2023-03-07
 */
@Service
public class EmpsalaryServiceImpl extends ServiceImpl<EmpsalaryMapper, Empsalary> implements IEmpsalaryService {

    @Resource
    EmpsalaryMapper empsalaryMapper;

    @Override
    public ResultVo page(int current, int pageSize, String name) {
        Page<Empsalary> pageInfo = new Page<>(current, pageSize);
        IPage<Empsalary> empsalarys = empsalaryMapper.getEmpsalaryBypage(pageInfo, name);
        return new ResultVo<Page>(true, "查询成功", empsalarys);
    }

    @Override
    public ResultVo getEmpSalaryById(Integer id) {
        Empsalary one = empsalaryMapper.selectById(id);
        if (one == null) {
            return new ResultVo(false, "查询失败");
        }
        return new ResultVo(true, "查询成功", one);
    }

    @Override
    public ResultVo getAll() {
        List<Empsalary> empsalaryList = empsalaryMapper.selectList(null);
        if (empsalaryList == null) {
            return new ResultVo(false, "查询失败");
        }
        return new ResultVo(true, "查询成功", empsalaryList);
    }

    @Override
    public ResultVo addEmpsalary(Empsalary empsalary) {
        int i = empsalaryMapper.insert(empsalary);
        if (i > 0) {
            return new ResultVo(true, "添加成功", empsalary);
        }
        return new ResultVo(false, "添加失败");
    }

    @Override
    public ResultVo updateEmpsalary(Empsalary empsalary) {
        int i = empsalaryMapper.updateById(empsalary);
        if (i > 0) {
            return new ResultVo(true, "修改成功", empsalary);
        }
        return new ResultVo(false, "修改失败");
    }

    @Override
    public ResultVo deleteEmpsalaryById(Integer id) {
        int i = empsalaryMapper.deleteById(id);
        if (i > 0) {
            return new ResultVo(true, "删除成功");
        }
        return new ResultVo(false, "修改失败");
    }


}
